package com.hq.controller;

import com.hq.entity.ResultVo;
import com.hq.entity.UserInfo;
import com.hq.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;
    // 登录
    @RequestMapping("/login")
    public ResultVo login(@RequestBody UserInfo userInfo){
        log.info("用户名：{}",userInfo.getUserName());
        ResultVo vo = new ResultVo();
        UserInfo user = userService.login(userInfo);
        if(user != null){
            vo.setCode(200);
            vo.setData(user);
        }else{
            vo.setCode(500);
            vo.setMsg("登录账号或密码有误");
        }
        return vo;
    }

    /**
     * 修改密码
     * @param userInfo
     * @return
     */
    @RequestMapping("/changePwd")
    public ResultVo changePwd(@RequestBody UserInfo userInfo){
        log.info("用户名：{}",userInfo.getUserName());
        ResultVo vo=new ResultVo();
        if(userService.updatePwd(userInfo)>0){
            vo.setCode(200);
            vo.setMsg("密码修改成功！");
        }else{
            vo.setCode(500);
            vo.setMsg("密码修改失败！");
        }
        return vo;
    }
}
